import { getChannelsApi, getArticlesApi, addArticleApi, editArticleApi, getArticleApi } from '@/api/article'

// 获取频道
export const getChannels = () => {
    return async dispatch => {
        const data = await getChannelsApi()
        dispatch({ type: 'article/setChannels', payload: data.channels })
    }
}

// 获取文章列表
export const getArticles = params => {
    return async dispatch => {
        const data = await getArticlesApi(params)
        dispatch({ type: 'article/setArticles', payload: data })
    }
}

// 发布文章
export const addArticle = params => {
    return async dispatch => {
        const data = await addArticleApi(params)
        return data
    }
}

// 编辑文章
export const editArticle = (params, draft = false) => {
    return async dispatch => {
        const data = await editArticleApi(params, draft)
        return data
    }
}

// 获取文章
export const getArticle = id => {
    return async dispatch => {
        const data = await getArticleApi(id)
        return data
    }
}